﻿using CloudMusic.Helper;
using CloudMusic.Model;
using DMSkin.Core.MVVM;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CloudMusic.ViewModel
{
    public class PageBoutiqueSheetViewModel: ViewModelBase
    {
        public static event EventHandler PushData;
        List<Boutique> bq = null;
        private ObservableCollection<Boutique> boutique;
        public ObservableCollection<Boutique> Boutique
        {
            get
            {
                if (boutique == null)
                {
                    boutique = new ObservableCollection<Boutique>();
                }
                return boutique;
            }
            set
            {
                boutique = value;
                //MainMusicList = songSheetList;
                OnPropertyChanged("Boutique");
            }
        }
        private string tagName;
        public string TagName
        {
            get { return tagName; }
            set { tagName = value;OnPropertyChanged("TagName"); }
        }
        public PageBoutiqueSheetViewModel() { }
        public PageBoutiqueSheetViewModel(string tag,long time) 
        {

            boutColuns = 2;
            TagName = tag;
            bq = new List<Boutique>();
            GetData(tag, time);
        }
        private int boutColuns;
        public int BoutColuns
        {
            get { return boutColuns; }
            set { boutColuns = value; OnPropertyChanged("BoutColuns"); }
        }
        private void GetData(string tag,long time) 
        {
            var list = CommonHelper.GetEquipList<BoutiqueSheetModel>(1,"http://localhost:3000/top/playlist/highquality?cat=" + tag + "&before=" + time + "&limit=30");
            foreach (PlaylistsItem jo in list.playlists)
            {
                var bout = new Boutique
                {
                    SheetType = true,
                    SheetId = Convert.ToInt64(jo.id.ToString()),
                    UserId = Convert.ToInt64(jo.creator.userId.ToString()),
                    Tag = jo.tag.ToString(),
                    BkUrl = jo.coverImgUrl.ToString(),
                    Copywriter = jo.copywriter.ToString(),
                    NickName = jo.creator.nickname.ToString(),
                    Icon = Convert.ToInt32(jo.creator.userType.ToString()),
                    Time = Convert.ToInt64(jo.updateTime.ToString()),
                    Count = CommonHelper.GetPlayCount(Convert.ToInt64(jo.playCount.ToString())),
                    Name = jo.name.ToString()
                };
                Boutique.Add(bout);
            }
        }
    }
}
